﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Entities;
using WebUI.Areas.Bots.Binders;
using WebUI.Areas.Bots.Models;
using WebUI.Areas.Reports.Binders;
using log4net.Config;

namespace WebUI
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            XmlConfigurator.Configure();
            filters.Add(new LogExceptionFilterAttribute());
            filters.Add(new HandleErrorAttribute ());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                 "default",
                 "{controller}/{action}",
                 new { controller = MVC.Reports.Reports.Name, action = MVC.Reports.Reports.ActionNames.Index },
                 new string[] { "RoutingIssue.Areas.Site.Controllers" }
             ).DataTokens.Add("Area", MVC.Reports.Name);
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            ModelValidatorProviders.Providers.Clear();
            ModelValidatorProviders.Providers.Add(new DataAnnotationsModelValidatorProvider());
            ModelBinders.Binders.Add(typeof(UsersMachinesSetting), new UsersMachinesSettingBinder());
            ModelBinders.Binders.Add(typeof(NotificationSetting), new NotificationSettingBinder());
            ModelBinders.Binders.Add(typeof(FilterOperations), new FilterOperationsBinder());
        }
    }
}